package com.xuqm.sdhbwfu.app.ui

import android.content.Intent
import androidx.activity.viewModels
import com.xuqm.base.common.GsonImplHelp
import com.xuqm.base.common.ToolsHelper
import com.xuqm.base.dialog.loading.LoadingDialog
import com.xuqm.base.extensions.showMessage
import com.xuqm.base.ui.BaseActivity
import com.xuqm.sdhbwfu.app.R
import com.xuqm.sdhbwfu.app.databinding.ActivityProcessingSkipBinding
import com.xuqm.sdhbwfu.app.model.JobListModel
import com.xuqm.sdhbwfu.app.viewmodel.ProcessingDetailViewModel
import com.xuqm.sdhbwfu.app.viewmodel.ProcessingSkipViewModel

class ProcessingSkipActivity : BaseActivity<ActivityProcessingSkipBinding>() {
    override fun getLayoutId(): Int = R.layout.activity_processing_skip
    override fun fullscreen(): Boolean =true
    private val vm: ProcessingSkipViewModel by viewModels()


    lateinit var model: JobListModel
    private var mId: Int = -1

    override fun initData() {
        super.initData()

        mId = intent.getIntExtra("mId", -1)
        val str = intent?.getStringExtra("item") ?: ""
        if (ToolsHelper.isNull(str)) {
            "数据传输错误".showMessage()
            finish()
        }
        model = GsonImplHelp.get().toObject(str, JobListModel::class.java)
    }

    override fun lateInitView() {
        super.lateInitView()

        binding.inspectionBackLyt.setOnClickListener { finish() }


        vm.up.observe(this) {
            LoadingDialog.dismissDialog()
            if (null != it) {
                setResult(
                    RESULT_OK,
                    Intent().apply { putExtra("item", GsonImplHelp.get().toJson(it)) })
                finish()
            }
        }

        binding.skipSkip.setOnClickListener {

            val content = binding.skpiContent.text.toString().toString()
            if(ToolsHelper.isNull(content)){
                "请输入跳过理由".showMessage()
                return@setOnClickListener
            }

            LoadingDialog.showDialog("")
            model.tip = content
            model.status = "skip"
            vm.inspectionUpdate(mId,model)
        }
    }
}